package com.bree.erp.jsf.vo;

import java.util.HashSet;
import java.util.Set;

import com.bree.erp.entity.GroupType;
import com.bree.erp.entity.Project;

public class PermissionDT {

	private Project project;
	
	private boolean admin;
	private boolean user;
	private boolean manager;
	private boolean purchaser;
	private boolean warehouse;
	
	public PermissionDT(Project project, Set<GroupType> groups) {
		
		this.project = project;
		
		if(groups != null) {
			// ADMIN, USER, MANAGER, PURCHASER, WAREHOUSE
			if(groups.contains(GroupType.ADMIN)) {
				admin = true;
			}
			if(groups.contains(GroupType.USER)) {
				user = true;
			}
			if(groups.contains(GroupType.MANAGER)) {
				manager = true;
			}
			if(groups.contains(GroupType.PURCHASER)) {
				purchaser = true;
			}
			if(groups.contains(GroupType.WAREHOUSE)) {
				warehouse = true;
			}
		}
	}
	
	public Set<GroupType> getGroups() {
		Set<GroupType> set = new HashSet<GroupType>();
		
		if(admin) {
			set.add(GroupType.ADMIN);
		}
		if(user) {
			set.add(GroupType.USER);
		}
		if(manager) {
			set.add(GroupType.MANAGER);
		}
		if(purchaser) {
			set.add(GroupType.PURCHASER);
		}
		if(warehouse) {
			set.add(GroupType.WAREHOUSE);
		}
		return set;
	}

	/**
	 * @return the project
	 */
	public Project getProject() {
		return project;
	}

	/**
	 * @param project the project to set
	 */
	public void setProject(Project project) {
		this.project = project;
	}

	/**
	 * @return the admin
	 */
	public boolean isAdmin() {
		return admin;
	}

	/**
	 * @param admin the admin to set
	 */
	public void setAdmin(boolean admin) {
		this.admin = admin;
	}

	/**
	 * @return the user
	 */
	public boolean isUser() {
		return user;
	}

	/**
	 * @param user the user to set
	 */
	public void setUser(boolean user) {
		this.user = user;
	}

	/**
	 * @return the manager
	 */
	public boolean isManager() {
		return manager;
	}

	/**
	 * @param manager the manager to set
	 */
	public void setManager(boolean manager) {
		this.manager = manager;
	}

	/**
	 * @return the purchaser
	 */
	public boolean isPurchaser() {
		return purchaser;
	}

	/**
	 * @param purchaser the purchaser to set
	 */
	public void setPurchaser(boolean purchaser) {
		this.purchaser = purchaser;
	}

	/**
	 * @return the warehouse
	 */
	public boolean isWarehouse() {
		return warehouse;
	}

	/**
	 * @param warehouse the warehouse to set
	 */
	public void setWarehouse(boolean warehouse) {
		this.warehouse = warehouse;
	}
	
	
	
}
